package com.knowledge.review.designPatterns.creatormode.BuilderPattern;

import lombok.Data;

/**
 * @author xufw
 */ //产品类 电脑   常规写法
@Data
public class Computer {
    private String motherboard;
    private String cpu;
    private String memory;
    private String disk;
    private String gpu;
    private String power;
    private String heatSink;
    private String chassis;
}

// 抽象 builder类（接口） 组装电脑
//interface ComputerBuilder {
//    Computer computer = new Computer();
//
//    void buildMotherboard();
//
//    void buildCpu();
//
//    void buildMemory();
//
//    void buildDisk();
//
//    void buildGpu();
//
//    void buildHeatSink();
//
//    void buildPower();
//
//    void buildChassis();
//
//    Computer build();
//}

/*
*  第二种写法
*/
//class SimpleComputerBuilder {
//    private Computer computer = new Computer();
//    public void buildMotherBoard(String motherBoard){
//        computer.setMotherboard(motherBoard);
//    }
//    public void buildCpu(String cpu){
//        computer.setCpu(cpu);
//    }
//    public void buildMemory(String memory){
//        computer.setMemory(memory);
//    }
//    public void buildDisk(String disk){
//        computer.setDisk(disk);
//    }
//    public void buildGpu(String gpu){
//        computer.setGpu(gpu);
//    }
//    public void buildPower(String power){
//        computer.setPower(power);
//    }
//    public void buildHeatSink(String heatSink){
//        computer.setHeatSink(heatSink);
//    }
//    public void buildChassis(String chassis){
//        computer.setChassis(chassis);
//    }
//    public Computer build(){
//        return computer;
//    }
//}

/*
 *  第三种写法~链式写法建造者类
 */
class SimpleComputerBuilder {
    private Computer computer = new Computer();
    public SimpleComputerBuilder buildMotherBoard(String motherBoard){
        computer.setMotherboard(motherBoard);
        return this;
    }
    public SimpleComputerBuilder buildCpu(String cpu){
        computer.setCpu(cpu);
        return this;
    }
    public SimpleComputerBuilder buildMemory(String memory){
        computer.setMemory(memory);
        return this;
    }
    public SimpleComputerBuilder buildDisk(String disk){
        computer.setDisk(disk);
        return this;
    }
    public SimpleComputerBuilder buildGpu(String gpu){
        computer.setGpu(gpu);
        return this;
    }
    public SimpleComputerBuilder buildPower(String power){
        computer.setPower(power);
        return this;
    }
    public SimpleComputerBuilder buildHeatSink(String heatSink){
        computer.setHeatSink(heatSink);
        return this;
    }
    public SimpleComputerBuilder buildChassis(String chassis){
        computer.setChassis(chassis);
        return this;
    }
    public Computer build(){
        return computer;
    }
}

// 具体 builder类 华硕ROG全家桶电脑（手动狗头）
//class AsusComputerBuilder implements ComputerBuilder {
//    @Override
//    public void buildMotherboard() {
//        computer.setMotherboard("Extreme主板");
//    }
//
//    @Override
//    public void buildCpu() {
//        computer.setCpu("Inter 12900KS");
//    }
//
//    @Override
//    public void buildMemory() {
//        computer.setMemory("芝奇幻峰戟 16G*2");
//    }
//
//    @Override
//    public void buildDisk() {
//        computer.setDisk("三星980Pro 2T");
//    }
//
//    @Override
//    public void buildGpu() {
//        computer.setGpu("华硕3090Ti 水猛禽");
//    }
//
//    @Override
//    public void buildHeatSink() {
//        computer.setHeatSink("龙神二代一体式水冷");
//    }
//
//    @Override
//    public void buildPower() {
//        computer.setPower("雷神二代1200W");
//    }
//
//    @Override
//    public void buildChassis() {
//        computer.setChassis("太阳神机箱");
//    }
//
//    @Override
//    public Computer build() {
//        return computer;
//    }
//}

// 指挥者类 指挥该组装什么电脑
//@AllArgsConstructor
//class ComputerDirector {
//    private ComputerBuilder computerBuilder;
//
//    public Computer construct() {
//        computerBuilder.buildMotherboard();
//        computerBuilder.buildCpu();
//        computerBuilder.buildMemory();
//        computerBuilder.buildDisk();
//        computerBuilder.buildGpu();
//        computerBuilder.buildHeatSink();
//        computerBuilder.buildPower();
//        computerBuilder.buildChassis();
//        return computerBuilder.build();
//    }
//}

class Test {
    // 测试
//    public static void main(String[] args) {
//        ComputerDirector computerDirector = new ComputerDirector(new AsusComputerBuilder());
//        // Computer(motherboard=Extreme主板, cpu=Inter 12900KS, memory=芝奇幻峰戟 16G*2, disk=三星980Pro 2T, gpu=华硕3090Ti 水猛禽, power=雷神二代1200W, heatSink=龙神二代一体式水冷, chassis=太阳神机箱)
//        System.out.println(computerDirector.construct());
//    }
    // 测试

//    第二种写法
//    public static void main(String[] args) {
//        SimpleComputerBuilder simpleComputerBuilder = new SimpleComputerBuilder();
//        simpleComputerBuilder.buildMotherBoard("Extreme主板");
//        simpleComputerBuilder.buildCpu("Inter 12900K");
//        simpleComputerBuilder.buildMemory("芝奇幻峰戟 16G*2");
//        simpleComputerBuilder.buildDisk("三星980Pro 2T");
//        simpleComputerBuilder.buildGpu("华硕3090Ti 水猛禽");
//        simpleComputerBuilder.buildPower("雷神二代1200W");
//        simpleComputerBuilder.buildHeatSink("龙神二代一体式水冷");
//        simpleComputerBuilder.buildChassis("太阳神机箱");
//        // Computer(motherboard=Extreme主板, cpu=Inter 12900K, memory=芝奇幻峰戟 16G*2, disk=三星980Pro 2T, gpu=华硕3090Ti 水猛禽, power=雷神二代1200W, heatSink=龙神二代一体式水冷, chassis=太阳神机箱)
//        System.out.println(simpleComputerBuilder.build());
//    }

//    第三种写法
// 测试
public static void main(String[] args) {
    Computer asusComputer = new SimpleComputerBuilder().buildMotherBoard("Extreme主板")
            .buildCpu("Inter 12900K")
            .buildMemory("芝奇幻峰戟 16G*2")
            .buildDisk("三星980Pro 2T")
            .buildGpu("华硕3090Ti 水猛禽")
            .buildPower("雷神二代1200W")
            .buildHeatSink("龙神二代一体式水冷")
            .buildChassis("太阳神机箱").build();
    System.out.println(asusComputer);
}
}